package com.example.controller;

import com.example.bean.Role;
import com.example.bean.User;
import com.example.service.UserService;
import com.example.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lianlei on 2017/1/12.
 */
@RestController
public class UserController {

    private UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

     @RequestMapping(value = "/login" , method = RequestMethod.POST)
     @ResponseBody
    public Result login(@RequestBody User user, HttpServletRequest request) throws Exception {
        Result result = userService.loginByUser(user , request);
        return result;
    }

    @RequestMapping(value = "/registered" , method = RequestMethod.POST)
    @ResponseBody
    public Result registered(@RequestBody User user){
        Result result = userService.registered(user);
        return result;
    }

    @RequestMapping(value = "/role" , method = RequestMethod.POST)
    @ResponseBody
    public Result addRole(@RequestBody Role role){
        return userService.addRoles(role);
    }
}
